package message;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.connection.RedisServer;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.concurrent.CountDownLatch;

/**
 * Created by yanxi on 2018/4/15 0015.
 */
//@Service("myListener")
public class MyListener{

    private CountDownLatch latch;

    /**
     * 方便测试的时候等待接收消息
     * @param latch
     */
    @Autowired
    public MyListener(CountDownLatch latch){
        this.latch = latch;
    }

    /**
     * 订阅者
     * @param message
     */
    public void receiveMessage(Object message,String chanl) {
        System.out.println(new String(message.toString()));
        latch.countDown();
    }

}
